倒數計時器
let countdown;
const timerDisplat = document.querySelector('.display__time-left')
const endTime=document.querySelector('display__end-time')
const buttons = document.querySelectorAll('[data-time]')
function timer(seconds){
clearInterval(countdown)
const now = Date.now();
const then = now+ seconds* 1000;
countdown = setInterval(()=>{
const secondsLeft = Math.round((then - Date.now()) / 1000)
if(secondsLeft <=0 ){
clearInterval(countdown)
return;
}
},1000)
}
function dispaltTimeLeft(seconds){
const minutes = Math.floor(seconds/60);
const remainderSeconds = seconds % 60
}
const display=`${minutes}:${remainderSeconds <10 ?'0':''}${remainderSeconds}`
document.title=display
timeeDisplay.textContent=display
function displayEndTime(timestamp){
const end=new.Date(timestamp);
const hour = end.getHours();
const adjustHour=hour>12?hour-12:hour
const minutes = end.getMinutes();
endTime.textContent=`be back at ${adjustedHour}:${minutes <10 ?'0':""}${minutes}`
}
function startTimer(){
const seconds = parseInt(this.dataset.time)
}
buttons.forEach(button =>
button.addEventListenter('click',startTimer)
)
document.customForm.addEventListener('submit',function(e){
e.perventDefault();
const mins = this.minutes.value
timer(mins*60);
this.reset()
})